﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Chapter05.View
{
    /// <summary>
    /// DragAndDropWindow.xaml 的交互逻辑
    /// </summary>
    public partial class DragAndDropWindow : Window
    {
        public DragAndDropWindow()
        {
            InitializeComponent();
        }

        private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
        {
            var lbl = sender as TextBlock;
            if (lbl != null)
            {
                DragDrop.DoDragDrop(lbl, lbl.Text, DragDropEffects.Copy);
            }
        }

        private void Label_Drop(object sender, DragEventArgs e)
        {
            var label = sender as Label;
            if (label != null)
            {
                label.Content = e.Data.GetData(DataFormats.Text);
            }
        }

        private void Label_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.Text))
                e.Effects = DragDropEffects.Copy;
            else
                e.Effects = DragDropEffects.None;
        }
    }
}
